import request from '@/utils/request'
import { commonList, commonAdd, commonEdit, commonBatchDelete, commonDetail } from '../_common'

//api controller根路径，前后不带 /
const controller = 'media';

//单个提交
export function submit(mediaId, selectCatalogId) {
  return request({
    url: `/media/${mediaId}/submit`,
    method: 'put',
    data: "targetCatalogId=" + selectCatalogId
  })
}
//批量提交
export function batchSubmit(data) {
  return request({
    url: `/medias/submit`,
    method: 'post',
    data
  })
}
//待我审核
export function myprocess(params) {
  return request({
    url: '/media/myprocess',
    method: 'get',
    params
  })
}

export function myflow(params) {
  return request({
    url: '/media/myflow',
    method: 'get',
    params
  })
}
//单个驳回
export function reject(mediaId, params) {
  return request({
    url: `/media/${mediaId}/reject`,
    method: 'get',
    params
  })
}
//批量驳回
export function batchReject(data) {
  return request({
    url: `/medias/reject`,
    method: 'post',
    data
  })
}

export function rejectReason(mediaId) {
  return request({
    url: `/media/${mediaId}/rejectreason`,
    method: 'get'
  })
}
//单个通过
export function pass(mediaId, params) {
  return request({
    url: `/media/${mediaId}/pass`,
    method: 'get',
    params
  })
}
//批量审批通过
export function batchPass(data) {
  return request({
    url: `/medias/pass`,
    method: 'post',
    data
  })
}
//单个撤回
export function callback(mediaId) {
  return request({
    url: `/media/${mediaId}/call-back`,
    method: 'put'
  })
}
//批量撤回
export function batchCallback(data) {
  return request({
    url: `/medias/call-back`,
    method: 'post',
    data
  })
}

export function detail(mediaId) {
  return request({
    url: `/media/${mediaId}`,
    method: 'get'
  })
}

export function deleteApply(mediaId) {
  return request({
    url: `/media/${mediaId}/flow`,
    method: 'DELETE'
  })
}

export function deleteProcess(mediaProcessId) {
  return request({
    url: `/media/${mediaProcessId}/process`,
    method: 'DELETE'
  })
}

export function getLabel(mediaId) {
  return request({
    url: `/media/${mediaId}/tag`,
    method: 'get',
  })
}

export function download(mediaId) {
  return request({
    url: `/media/${mediaId}/download-url`,
    method: 'get',
  })
}

export function exist(mediaIds) {
  return request({
    url: `/medias/${mediaIds}/exist`,
    method: 'get',
  })
}

export function getPassDetail(mediaId) {
  return request({
    url: `/media/flow/getPassDetail/${mediaId}`,
    method: 'get'
  })
}

export function saveLabel(mediaId, label, categoryName) {
  return request({
    url: `/media-flow/${mediaId}/tag`,
    method: 'put',
    data: `tagName=${label}&categoryName=${categoryName}`
  })
}

export function deleteLabel(mediaId, label) {
  return request({
    url: `/media-flow/${mediaId}/tag?tagName=${label}`,
    method: 'DELETE',
  })
}

export function saveCategory(categoryName) {
  return request({
    url: `/media-flow/tag/TagCategory?categoryName=${categoryName}`,
    method: 'get',
  })
}

export function edit(id, data) {
  return commonEdit('media-flow')(id, data);
}

export function rename(mediaId, data) {
  return request({
    url: `/media-flow/${mediaId}/rename`,
    method: 'put',
    data: "mediaName=" + data.mediaName
  })
}

/**
 * 批量删除
 * @param ids 要删除的数据id数组，[id1, id2, id3]
 */
export function batchDelete(mediaIds) {
  return request({
    url: `/media/flow/deleteMore`,
    method: 'post',
    data:mediaIds
  })
}